package com.zlm.weather.quartz;

import com.zlm.weather.pojo.Province;
import com.zlm.weather.service.CityService;
import com.zlm.weather.service.WeatherService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.List;

/**
 * @Author: 郑
 * @Date: Create in 2020-1-18.
 */
@Slf4j
public class WeatherDataSyscJob extends QuartzJobBean {

    @Autowired
    private CityService cityService;
    @Autowired
    private WeatherService weatherService;
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
            log.info("天气同步Job,start!");
            //获取城市列表
        List<Province> provinceList = null;
        try{
            provinceList = cityService.listProvince();
        }catch (Exception e){
            log.error("获取主要城市出错:{}",e);
        }
        for (Province province : provinceList) {
            String cityName = province.getCityName();
            log.info("天气数据同步，cityName：{}",cityName);
            weatherService.getDataByCityName(cityName);
        }
        log.info("天气数据同步Job,End!");

    }
}
